<template>
  <div class="login">
    <div class="login-center">
      <div class="login-left">
        <div>欢迎管理员登录</div>
        <div>
          <img src="../../assets/img/login/admin.svg" alt="" />
        </div>
        <div>
          <input type="button" value="用户登录" @click="adminCli" />
        </div>
      </div>
      <div class="login-right">
        <div>欢迎用户登录</div>
        <div>
          <img src="../../assets/img/login/user.svg" alt="" />
        </div>
        <div>
          <input type="button" value="管理员登录" @click="userCli" />
        </div>
      </div>
      <div class="login-dong" :style="{ left: isUser ? '2%' : '50%' }">
        <div v-if="uadmin == 0">管理员登录</div>
        <div v-else>用户登录</div>
        <div>
          <input type="text" placeholder="请输入账号" v-model="act" />
        </div>
        <div>
          <input type="password" placeholder="请输入密码" v-model="paw" />
        </div>
        <div class="login-user" v-if="uadmin">
          <div>
            <input type="button" value="登录" @click="logins" />
            <input type="button" value="注册" @click="register" />
          </div>
          <div @click="forget">忘记密码</div>
        </div>
        <div class="login-admin" v-else>
          <input type="button" value="登录" @click="logins" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { testLogin } from "../../network/login";

export default {
  name: "Login2",
  data() {
    return {
      isUser: true,
      act: "",
      paw: "",
      uadmin: 1,
    };
  },
  methods: {
    userCli() {
      this.isUser = false;
      this.uadmin = 0;
      this.act = "";
      this.paw = "";
    },

    adminCli() {
      this.isUser = true;
      this.uadmin = 1;
      this.act = "";
      this.paw = "";
    },

    logins() {
      testLogin(this.uadmin, this.act, this.paw).then((res) => {
        if (res.data.code == 200) {
          this.$Cookie.set("userid", res.data.data.uid, { expires: 7 });
          if (res.data.data.uadmin == 1) {
            this.$router.back();
          } else if (res.data.data.uadmin == 0) {
            this.$Cookie.set("uadmin", res.data.data.uadmin, { expires: 7 });
            this.$router.push("/admin");
          }
        } else {
          this.$message({
            showClose: true,
            message: "手机号或密码错误",
            type: "error",
          });
        }
      });
    },

    register() {
      this.$router.push("/register");
    },

    forget() {
      this.$router.push("/forget");
    },
  },
};
</script>

<style>
.login {
  width: 100%;
  height: 100vh;
  background-image: url("../../assets/img/bg/bg5.jpg");
  background-repeat: no-repeat;
  background-size: 100% 100%;
  display: flex;
  align-items: center;
}

.login-center {
  position: relative;
  width: 45%;
  margin: 0 auto;
  height: 40vh;
  background-color: rgba(122, 198, 226, 0.8);
  display: flex;
}

.login-left,
.login-right {
  flex: 1;
  background-color: rgba(255, 255, 255, 0.8);
  text-align: center;
  border-radius: 0.025rem;
}

.login-left img,
.login-right img {
  width: 45%;
}

.login-left div:nth-child(1),
.login-right div:nth-child(1) {
  margin-top: 0.1rem;
  font-size: 0.12rem;
  margin-bottom: 0.1rem;
}

.login-left div:nth-child(3),
.login-right div:nth-child(3) {
  margin-top: 0.1rem;
}

.login-left div:nth-child(3) input,
.login-right div:nth-child(3) input {
  color: #ffff;
  background-color: rgb(98, 199, 250);
  padding: 0.06rem 0.1rem;
  border-radius: 0.03rem;
  cursor: pointer;
}

.login-dong {
  position: absolute;
  z-index: 9999;
  width: 48%;
  height: 50vh;
  top: -5vh;
  left: 2%;
  background-color: rgb(133, 187, 231);
  transition: all 0.5s;
  text-align: center;
  border-radius: 0.05rem;
}

.login-dong div:nth-child(1) {
  margin-top: 0.3rem;
  margin-bottom: 0.3rem;
  font-size: 0.12rem;
}

.login-dong div:nth-child(2) {
  margin-bottom: 0.2rem;
}

.login-dong div:nth-child(2) input,
.login-dong div:nth-child(3) input {
  width: 60%;
  border: none;
  border-bottom: 1px solid rgb(212, 239, 250);
  background-color: transparent;
  outline: none;
  padding: 0.05rem;
}
.login-dong div:nth-child(2) input::-webkit-input-placeholder,
.login-dong div:nth-child(3) input::-webkit-input-placeholder {
  /* placeholder颜色 */
  color: #ffff;
}

.login-user div:nth-child(1) {
  margin: 0 auto;
  margin-top: 0.2rem;
  margin-bottom: 0.15rem;
  width: 60%;
  display: flex;
  justify-content: space-around;
}

.login-user div:nth-child(1) input {
  padding: 0.06rem 0.12rem;
  border-radius: 0.025rem;
  color: #ffffff;
  background-color: rgb(79, 164, 255);
  cursor: pointer;
}

.login-user div:nth-child(2) {
  color: rgb(126, 142, 158);
  cursor: pointer;
}

.login-user div:nth-child(2):hover {
  color: rgb(114, 113, 113);
}

.login-admin input {
  width: 30%;
  color: #ffffff;
  background-color: rgb(79, 164, 255);
  padding: 0.06rem 0.1rem;
  margin-top: 0.25rem;
  border-radius: 0.02rem;
  cursor: pointer;
}
</style>